#! /usr/bin/env python
# -*- coding: utf-8 -*-

# *************************************************************
#  Copyright (c) JoinQuant Development Team
#
#  Author: Huayong Kuang <kuanghuayong@joinquant.com>
#  CreateTime: 2017-11-18 14:30:46 Saturday
# *************************************************************

import sys
import argparse

class MyArgumentParser(argparse.ArgumentParser):
    def error(self, message):
        self.print_help(sys.stderr)
        self.exit(0, '%s: error: %s\n' % (self.prog, message))

def main():
    parser = MyArgumentParser(description='Simple example')
    parser.add_argument("-v", "--version", action="version", version="0.0.1", help="Print version")
    parser.add_argument("-t", "--test", action="store_true", required=True, help="This is test")
    parser.add_argument("-f", "--foo", help="This is test")
    subs = parser.add_subparsers(title="subparsers", dest="subparser")
    sub_one = subs.add_parser('one', help='does something')
    sub_one.add_argument("-t", "--test")
    sub_two = subs.add_parser('two', help='does something else')
    sub_two = sub_two.add_argument('-t', '--test')

    args = parser.parse_args()
    print(args)
    print(args.subparser)

if __name__ == '__main__':
    main()

